home *** CD-ROM | disk | FTP | other *** search
- /** Class EcommEditor
- Description : Implement the interface for Ecomm.
- Instantiates all window classes (Images, Thumnail, PhotPage)
- */
-
- /*
- @param editedElem, a Ecomm reference
- @param document, a object that supperts write/writeln (typically a browser document)
- */
- function NOF_Ecomm_MainWindow( _editedElement, _document, _name ) {
- this.__proto__ = NOF_Ecomm_MainWindow.prototype;
- this.SUPER( _editedElement, _document, _name );
-
- this.tempEditedElement = _editedElement;
- this.tempDocument = _document;
- this.defaultName = "ECOMMERCE_EDITOR";
- }
- NOF_Ecomm_MainWindow.inherits ( NOF.HTML.TabbedMenuEditorWindow );
- function NOF_Ecomm_MainWindow_ProtoBuilder() {
- var method = NOF_Ecomm_MainWindow.prototype;
-
- //event handlers
- method.onInit = function onInit(){
- //timesXXX += "Startup: " + ( (new Date()).getTime() - startTimeOD )+ "\n";
- //timesXXX += "loading: " + (new Date()).getTime() + "\n";
- log.info("before loading editedElement");
- this.editedElement.load();
- log.info("after loading editedElement");
- //timesXXX += "loaded: " + (new Date()).getTime() + "\n";
- var store = this.loadStore();
- log.info("after loading store");
- this.setOverridingResource(store);
- log.info("loading NOF.ecomm.products.MainWindow ");
- this.productsEditor = new NOF.ecomm.products.MainWindow ( this.editedElement, this.document);
- log.info("loading NOF.ecomm.listpage.MainWindow ");
- this.listPageEditor = new NOF.ecomm.listpage.MainWindow ( this.editedElement, this.document);
- log.info("loading NOF.ecomm.detailpage.MainWindow ");
- this.detailPageEditor = new NOF.ecomm.detailpage.MainWindow ( this.editedElement, this.document);
- log.info("loading NOF.ecomm.StoreEditor ");
- this.storeEditor = new NOF.ecomm.StoreEditor ( this.editedElement, this.document);
- log.info("NOF.ecomm.StoreEditor loaded");
- this.addChild( this.productsEditor );
- this.addChild( this.listPageEditor );
- this.addChild( this.detailPageEditor );
- this.addChild( this.storeEditor );
-
- this.productsEditor.addListener( this.listPageEditor );
- this.storeEditor.addListener(this.productsEditor);
- this.storeEditor.addListener(this);
-
- //initialize main tabbed menu
- var tabbedMenu = new NOF.UI.TabbedMenu("ecMainMenu", "NOF.EC_MainMenu", this);
- // for compatibility (should be rewritten to use HTMLDoc)
- tabbedMenu.setDocument (this.document);
- log.info("adding NOF.EcommTabMenuItem ");
- tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.productsEditor.getName(), this.getResourceProperty("products.title"), this.getApp()) );
- tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.listPageEditor.getName(), this.getResourceProperty("listPage.title"), this.getApp()) );
- tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.detailPageEditor.getName(), this.getResourceProperty("detailPage.title"), this.getApp()) );
- tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.storeEditor.getName(), this.getResourceProperty("store.title"), this.getApp()) );
- tabbedMenu.addListener( this ); //adds it to all menu items
- this.setMenu ( tabbedMenu );
- NOF.addVariable ("EC_MainMenu", tabbedMenu);
- log.info("menuitems added");
- this.productsEditor.init();
-
- this.listPageEditor.init();
- this.detailPageEditor.init();
- log.info("editors init finshed");
- this.super_onInit(); //this is implemented in base class and simply notifies the listners that this window has intitialised
- }
-
- method.onLoad = function onLoad() {
- this.setTitle (this.getResourceProperty("products.dialog.title"));
- var width = this.getResourceProperty('mainwindow.width') || 630;
- var height = this.getResourceProperty('mainwindow.height') || 470;
-
- this.setSize(width, height);
- //timesXXX += "initializing: " + (new Date()).getTime() + "\n";
-
- this.doc.initialize(this);
-
- //timesXXX += "initialized: " + ( new Date() ).getTime() + "\n";
- //timesXXX += "Total: " + ( (new Date()).getTime() - startTimeOD )+ "\n";
- //alert ( timesXXX );
-
- var tabbedMenu = this.getMenu();
- tabbedMenu.selectItem( tabbedMenu.getItem( this.productsEditor.getName()) );
-
- this.productsEditor.onLoad();
- this.listPageEditor.onLoad();
- this.detailPageEditor.onLoad();
- this.storeEditor.onLoad();
- this.productsEditor.show();
- //this.detailPageEditor.show();
- }
-
- method.onDone = function onDone() {
- this.onSave();
- window.close();
- }
-
- method.onSave = function onSave() {
- this.productsEditor.onSave();
- this.listPageEditor.onSave();
- this.detailPageEditor.onSave();
- this.storeEditor.onSave();
- this.editedElement.save( true );
-
- //TODO: tie it to the actual editors status!!
- NOF.App.getFSIApp().IntArg = 3; //means that both index & display are modified
- }
-
- method.onUnload = function onUnload() {
- this.detailPageEditor.onUnload();
- this.listPageEditor.onUnload();
- this.editedElement.prepareForPublish();
- NOF.App.getFSIApp().IntArg = 3; //means that both index & display are modified
- // once the ecomm editor dialog loaded it should never return cancel and
- // as such disappear from the page
- NOF.App.cancelScript(false);
- }
-
- method.onSaveProfile = function onSaveProfile() {
- result = window.showModalDialog("dialogs/profiles/managerDlg.html", [NOF, this, this.getEditedElement()], "status:no;help:no;border:thin;dialogWidth:280px;dialogHeight:260px;center:yes;scroll:no;");
- }
-
- /*
- * onUpdateData
- * @param evt an event of NOF.WindowEvent.DATAUPDATE_TO_CTRL or NOF.WindowEvent.DATAUPDATE_FROM_CTRL type
- */
- method.onUpdateData = function onUpdateData( direction ){
- this.listPageEditor.doDataUpdate( direction);
- this.detailPageEditor.doDataUpdate( direction );
- }
-
- method.super_actionPerformed = method.actionPerformed;
- /** actionPerformed
- @param evt name.
- */
- method.actionPerformed = function actionPerformed( evt ) {
- if ( evt instanceof NOF.StoreEvent ){
- if (evt.getID() == "CURRENCY_CHANGED") {
- this.updatePricing(this.storeEditor.store);
- }
- else if (evt.getID() == "WEIGHT_CHANGED") {
- this.updateWeightSystem(this.storeEditor.store);
- }
- else if (evt.getID() == "IMGUPLOAD_CHANGED") {
- this.forceUploadImages();
- }
- else {
- //var store = this.loadStore();
- var oldResPath = this.getApp().getOverridingResourcePath();
- this.setOverridingResource(this.storeEditor.store);
- var newResPath = this.getApp().getOverridingResourcePath();
- if (oldResPath != newResPath) {
- this.doc.initialize(this);
- this.listPageEditor.displayItemsEditor.updateLabels();
- this.detailPageEditor.displayItemsEditor.updateLabels();
- }
- var listPageData = this.editedElement.getListPage();
- var detailPageData = this.editedElement.getDetailPage();
- if (this.storeEditor.store.type == NOF.Store.NO_STORE) {
- //this.editedElement.setLabelDefaults();
- this.doc.cleanElementValue('listpage.purchaseoptions.displaybuy');
- this.doc.cleanElementValue('listpage.purchaseoptions.displayadd');
- this.doc.cleanElementValue('detailpage.purchaseoptions.displaybuy');
- this.doc.cleanElementValue('detailpage.purchaseoptions.displayadd');
- }
- else {
- var enableButtons = evt.getSource();
- if (enableButtons) {
- this.doc.setElementValue('listpage.purchaseoptions.displaybuy', 'yes');
- this.doc.setElementValue('listpage.purchaseoptions.displayadd', 'yes');
- this.doc.setElementValue('detailpage.purchaseoptions.displaybuy', 'yes');
- this.doc.setElementValue('detailpage.purchaseoptions.displayadd', 'yes');
- }
- }
- this.updatePricing(this.storeEditor.store, true);
- this.updateWeightSystem(this.storeEditor.store, true);
- }
- }
- else if ( !(evt instanceof NOF.ProductEvent) ) //ignore ProductEvent ones. this would be better handled via addXXXListener methods for specific events
- return this.super_actionPerformed( evt );
- }
-
- method.forceUploadImages = function forceUploadImages() {
- this.editedElement.forceUploadImages();
- }
-
- method.updateWeightSystem = function updateWeightSystem (store, isStoreChange) {
- var listPageData = this.editedElement.getListPage();
- var dItemsEx = listPageData.getDisplayedItemsEx();
- var detailPageData = this.editedElement.getDetailPage();
- var dItemsEx2 = detailPageData.getDisplayedItemsEx();
-
- if (isStoreChange &&
- !dItemsEx["weight"].isPostfixIncluded() && !dItemsEx["weight"].isPrefixIncluded() &&
- !dItemsEx2["weight"].isPostfixIncluded() && !dItemsEx2["weight"].isPrefixIncluded()) {
-
- var loc = this.getResourceProperty("store.defaultWeightSystemLocation");
- if (store.type != NOF.Store.NO_STORE) {
- var engine = store.getStoreEngine(NOF.App.getDefaultLocale());
- loc = engine.getDefaultWeightSystemLabelLocation ();
- }
- if (loc == "prefix") {
- dItemsEx["weight"].setPrefixIncluded (true);
- dItemsEx2["weight"].setPrefixIncluded (true);
- }
- else if (loc == "postfix") {
- dItemsEx["weight"].setPostfixIncluded (true);
- dItemsEx2["weight"].setPostfixIncluded (true);
- }
- }
-
- this.setPrePostLabel (dItemsEx["weight"], store.weightSystemLabel, store.weightSystem);
- this.setPrePostLabel (dItemsEx2["weight"], store.weightSystemLabel, store.weightSystem);
- }
-
- method.updatePricing = function updatePricing (store, isStoreChange) {
- var listPageData = this.editedElement.getListPage();
- var dItemsEx = listPageData.getDisplayedItemsEx();
- var detailPageData = this.editedElement.getDetailPage();
- var dItemsEx2 = detailPageData.getDisplayedItemsEx();
-
- if (isStoreChange &&
- !dItemsEx["price"].isPostfixIncluded() && !dItemsEx["price"].isPrefixIncluded() &&
- !dItemsEx2["price"].isPostfixIncluded() && !dItemsEx2["price"].isPrefixIncluded()) {
-
- var loc = this.getResourceProperty("store.defaultCurrencyLabelLocation");
- if (store.type != NOF.Store.NO_STORE) {
- var engine = store.getStoreEngine(NOF.App.getDefaultLocale());
- loc = engine.getDefaultCurrencyLabelLocation ();
- }
- if (loc == "prefix") {
- dItemsEx["price"].setPrefixIncluded (true);
- dItemsEx2["price"].setPrefixIncluded (true);
- }
- else if (loc == "postfix") {
- dItemsEx["price"].setPostfixIncluded (true);
- dItemsEx2["price"].setPostfixIncluded (true);
- }
- }
-
- this.setPrePostLabel (dItemsEx["price"], store.currencyLabel, store.currency);
- this.setPrePostLabel (dItemsEx2["price"], store.currencyLabel, store.currency);
- var items = ["retailprice","shipping","tax"];
- for (var i=0; i<3; i++) {
- this.setPrePostLabel (dItemsEx[items[i]], store.currencyLabel, store.currency);
- this.setPrePostLabel (dItemsEx2[items[i]], store.currencyLabel, store.currency);
- }
-
- }
-
- method.setPrePostLabel = function setPrePostLabel(dItemsElem, label, item) {
- var _label = "";
- if (label != null && label.length > 0) {
- _label = label;
- }
- else if (item != null && item.length > 0) {
- _label = this.getResourceProperty("fmtdlg.prepost.label." + item);
- if (_label == null || _label.length == 0)
- _label = item;
- }
- else
- _label = "";
- if (dItemsElem.isPostfixIncluded())
- dItemsElem.setPostfix(_label);
- if (dItemsElem.isPrefixIncluded())
- dItemsElem.setPrefix(_label);
- }
-
- method.loadStore = function loadStore () {
- var storeId = this.editedElement.getStoreTypeId();
- var store = new NOF.Store (storeId);
- store.load();
- return store;
- }
-
- method.setOverridingResource = function setOverridingResource (store) {
- if (store.type != NOF.Store.NO_STORE) {
- //alert(" " + store.type + " != " + NOF.Store.NO_STORE);
- var rPath = store.getStoreEngine(NOF.App.getDefaultLocale()).getLabelsPath();
- //alert(rPath);
- this.getApp().setOverridingResourcePath (rPath);
- } else {
- //alert(" " + store.type + " = " + NOF.Store.NO_STORE);
- this.getApp().clearOverridingResource();
- }
- }
-
- }
-
- NOF_Ecomm_MainWindow_ProtoBuilder();
-